package cz.proks.bank.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@NamedQueries ({
	@NamedQuery(name = "OperationLog.listByAccount", query = "SELECT ol FROM OperationLog ol WHERE ol.account = :account")
})
public class OperationLog implements Serializable {
	public enum OperationType { MONEY_WITHDRAW, MONEY_DEPOSIT, OUTGOING_PAYMENT, INGOING_PAYMENT, NEW_ACCOUNT, NEW_LOAN, LOAN_REPAYMENT }
	
	@Id @GeneratedValue
	private long id;
	
	@ManyToOne
	private Account account;
		
	@ManyToOne	
	private Bank bank;
	
	@Enumerated @Column(nullable = false)
	private OperationType type;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Date date;
	
	@Lob
	private String additionalInfo;
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	public Bank getBank() {
		return bank;
	}
	public void setBank(Bank bank) {
		this.bank = bank;
	}
	public OperationType getType() {
		return type;
	}
	public void setType(OperationType type) {
		this.type = type;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public String getAdditionalInfo() {
		return additionalInfo;
	}
	public void setAdditionalInfo(String additionalInfo) {
		this.additionalInfo = additionalInfo;
	}

	@Override
	public String toString() {
		return "OperationLog [id='" + id + "', account='" + account
				+ "', bank='" + bank + "', type='" + type + "', date='" + date
				+ "', additionalInfo='" + additionalInfo + "]";
	}		
}
